<template>
	<view style="padding-top: 40rpx;">
		<view v-if="pageType=='营业时间'">
			<view class="between oneLine topLine">
				<view>开店时间</view>
				<picker mode="time" :value="startTime" @change="bindTimeChange">
					<view><text>{{startTime}}</text>
						<uni-icons type="bottom" color="#999"></uni-icons>
					</view>
				</picker>
			</view>
			<view class="between oneLine">
				<view>打烊时间</view>
				<picker mode="time" :value="endTime" @change="bindEndTimeChange">
					<view><text>{{endTime}}</text>
						<uni-icons type="bottom" color="#999"></uni-icons>
					</view>
				</picker>
			</view>
		</view>
		<view v-if="pageType=='店铺电话'">
			<input type="number" class="input" :placeholder="`请输入店铺电话`"
				placeholder-style="color:#BBBBBB;font-size:28rpx" v-model="phone" maxlength="11"></input>
		</view>
		<button class="set-btn" form-type="submit" @click="onSub">保存</button>
	</view>
</template>

<script>
	import {
		setStoreMsg
	} from "../../../api/index.js"
	export default {
		data() {
			return {
				phone: '',
				startTime: '请选择',
				endTime: '请选择',
				pageType: '',
				bid: '',
			}
		},
		onLoad(opt) {
			this.bid = opt.bid
			this.pageType = opt.pagetype
			this.setNavTitle(this.pageType)
		},
		methods: {
			onSub() {
				let data
				switch (true) {
					case this.pageType == '店铺电话':
						if (!this.phone) {
							this.showToast('请输入电话号码')
						} else {
							data = {
								bid: this.bid,
								tel: this.phone
							}
							this.onSetStoreMsg(data)
						}
						break;
					case this.pageType == '营业时间':
						if (this.startTime == '请选择' || this.endTime == '请选择') {
							this.showToast('请选择营业时间')
						} else {
							data = {
								bid: this.bid,
								start_hours: this.startTime,
								end_hours: this.endTime
							}
							this.onSetStoreMsg(data)
						}
						break;
				}
			},
			// 修改店铺信息
			async onSetStoreMsg(val) {

				const res = await setStoreMsg(`s=/ApiBusiness/setinfo`, val)
				const {
					data,
					msg,
					status
				} = res.data
				this.showToast(msg)
				if (status == 1) {
					this.goBack(2000)
					console.log(res.data)
				}
			},
			bindTimeChange(e) {
				this.startTime = e.detail.value
			},
			bindEndTimeChange(e) {
				this.endTime = e.detail.value
			},

		}
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="scss" scoped>
	.input {
		background: #fff;
		height: 96rpx;
		padding: 0 30rpx;
		margin: 0 30rpx;
		// width: 85vw;

	}

	.set-btn {
		width: 90%;
		margin: 160rpx 5%;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 48rpx;
		color: #FFFFFF;
		font-weight: bold;
		background: #41644A;
	}

	text {
		color: #999;
		margin-right: 10rpx;
	}

	.topLine {
		border-bottom: 1px solid #f5f5f5;

	}

	.oneLine {
		background: #fff;
		color: #333;
		font-size: 34rpx;
		font-weight: 500;
		padding: 40rpx;
	}
</style>
